home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / test / string.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  5KB  |  151 lines

  1. /* Test class String
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    string.c,v $
  26.  * Revision 3.0  90/05/20  00:30:01  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/string.c,v 3.0 90/05/20 00:30:01 kgorlen Rel $";
  31.  
  32. #include "nihclconfig.h"
  33. #include "Range.h"
  34. #include "String.h"
  35.  
  36. main()
  37. {
  38.     cout << "\nTest Class String" << endl;
  39. cout << "String::String(char& c, unsigned l=1, unsigned extra): ";
  40.     String s1 = 'x';
  41.     cout << s1 << endl;            // "x"
  42.     String s2('x',25);
  43.     cout << s2 << endl;            // "xxxxxxxxxxxxxxxxxxxxxxxxx"
  44. cout << "String::String(): ";
  45.     String s3;
  46.     cout << s3.length() << ' ' << s3.capacity() << endl;    // 0 16
  47. cout << "String::String(unsigned storage): ";
  48.     String s9(100);
  49.     cout << s9.length() << ' ' << s9.capacity() << endl;    // 0 100
  50. cout << "String::String(const char*): ";
  51.     String s4 = "0123456789";
  52.     cout << s4 << ' ' << s4.capacity() << endl;    // "0123456789" 26
  53. cout << "String::String(const char*, unsigned extra): ";
  54.     String s8("0123456789",10);
  55.     cout << s8 << ' ' << s8.capacity() << endl;    // "0123456789" 20
  56. cout << "String::String(const String&): ";
  57.     String s5 = s4;
  58.     cout << s5 << endl;            // "0123456789"
  59. cout << "String::String(const String&, unsigned extra): ";
  60.     String s6(s4,0);
  61.     cout << s6 << endl;            // "0123456789"
  62. cout << "String::String(const SubString&):" << endl;
  63. cout << "SubString String::operator()(unsigned pos, unsigned lgt): ";
  64.     String s7 = s6(1,3);
  65.     cout << s7 << ' ' << s7.capacity() << endl;    // "123" 19
  66. cout << "String::String(const SubString&,  unsigned extra): ";
  67.     String s(s6(1,3),10);
  68.     cout << s << ' ' << s.capacity() << endl;    // "123" 13
  69. cout << "operator String::constCharPtTy(): ";
  70.     cout << strchr(s4,'4') << endl;        // "456789"
  71. cout << "SubString String::operator()(const Range& r): ";
  72.     cout << s6(Range(1,3)) << endl;        // "123"
  73. cout << "char& String::operator[](unsigned i): ";
  74. cout << "void String::operator=(const char*): ";
  75.     s = "0123456789";
  76.     s[0] = s[9];
  77.     cout << s << endl;            // "9123456789"
  78. cout << "unsigned String::length(): ";
  79.     s = "";
  80.     cout << s.length() << endl;        // 0
  81. cout << "unsigned String::size(): ";
  82.     cout << s.size() << endl;        // 0
  83. cout << "unsigned String::capacity(): ";
  84.     cout << s.capacity() << endl;        // 19
  85. cout << "unsigned String::reSize(unsigned new_capacity): ";
  86.     s.reSize(0);
  87.     cout << s.capacity() << endl;        // 0
  88. cout << "void String::operator=(const String&): ";
  89.     s = s4;
  90.     cout << s << endl;            // "0123456789"
  91.     s = s;
  92.     cout << s << endl;            // "0123456789"
  93. cout << "void String::operator=(const SubString&): ";
  94.     s = "87654321"; s.reSize(0);
  95.     s = s4(1,9);
  96.     cout << s << endl;            // "123456789"
  97.     s = s4;
  98.     s = s(0,9);
  99.     cout << s << endl;            // "012345678"
  100.     s = s4;
  101.     s = s(1,9);
  102.     cout << s << endl;            // "123456789"
  103. cout << "bool String::operator==(const String& s): ";
  104.     s = s4;
  105.     cout << (s == s4) << endl;        // 1
  106. cout << "bool String::operator<(const SubString ss): ";
  107.     cout << (s < s(1,9)) << endl;        // 1
  108. cout << "bool operator<(const char* cs): ";
  109.     cout << (s < "01234567890") << endl;    // 1
  110. cout << "friend bool operator<(const char* cs, const String& s): ";
  111.     cout << ("0123" < s) << endl;        // 1
  112. cout << "String String::operator&(const String& s): ";
  113.     s = s4;
  114.     cout << (s & s4) << endl;        // 01234567890123456789
  115. cout << "String String::operator&(const SubString& ss): ";
  116.     cout << (s & s4(1,9)) << endl;        // 0123456789123456789
  117. cout << "String String::operator&(const char* cs): ";
  118.     cout << (s & "xxx") << endl;        // 0123456789xxx
  119. cout << "friend String operator&(const char* cs, const String& s): ";
  120.     cout << ("xxx" & s) << endl;        // xxx0123456789
  121. cout << "friend String operator&(const char*, const SubString&): ";
  122.     cout << ("xxx" & s4(1,8)) << endl;    // xxx12345678
  123. cout << "String& String::operator&=(const String&): ";
  124.     s = s4; s.reSize(0);
  125.     s &= s4;
  126.     cout << s << endl;            // 01234567890123456789
  127. cout << "String& String::operator&=(const SubString&): ";
  128.     s = s4; s.reSize(0);
  129.     s &= s4(1,9);
  130.     cout << s << endl;            // 0123456789123456789
  131.     s = s4; s.reSize(0);
  132.     s &= s(1,9);
  133.     cout << s << endl;            // 0123456789123456789
  134. cout << "String& String::operator&=(const char* cs): ";
  135.     s = s4; s.reSize(0);
  136.     ((s &= "xxx") &= s8(0,1)) &= s1;
  137.     cout << s << endl;            // 0123456789xxx0x
  138. cout << "char& String::at(unsigned i): ";
  139.     s = "0123456789";
  140.     s.at(0) = s.at(9);
  141.     cout << s << endl;            // "9123456789"
  142. cout << "void String::toLower(): ";
  143.     s = "abcABC";
  144.     s.toLower();
  145.     cout << s << endl;            // "abcabc"
  146. cout << "void String::toUpper(): ";
  147.     s = "abcABC";
  148.     s.toUpper();
  149.     cout << s << endl;            // "ABCABC"
  150. }
  151.